﻿using System;
using System.Windows.Forms;
using LetsDoIt.Interfaces;
using LetsDoIt.Localization;

namespace LetsDoIt.Forms
{
	public partial class UserInfoForm : UserControl, INavigationForm
    {
        #region ctor
        public UserInfoForm()
		{
			InitializeComponent();
		}

		public UserInfoForm(MainForm hostForm, string identity)
		{
			HostForm = hostForm;
			Identity = identity;
			InitializeComponent();
        }
        #endregion ctor


        #region Implementation of INavigationForm

        public MainForm HostForm { get; set; }
		public string Identity { get; set; }
        public bool IsActive { get; set; }

		public void NavigationEnter(object sender)
		{
			//
			HostForm.mnuUserInfo.Enabled = false;
			//
			txtUserName.Text = HostForm.Settings.UserName;
            txtPassword.Text = HostForm.Settings.Password;
            //
		}

		public void NavigationLeave()
		{
			//nothing
			HostForm.mnuUserInfo.Enabled = true;
		}

		#endregion


        #region events

        private void btnBack_Click(object sender, EventArgs e)
		{
			HostForm.NavigateBack(this, string.Empty);
		}

		private void btnSave_Click(object sender, EventArgs e)
		{
			//save user info
			HostForm.Settings.UserName = txtUserName.Text;
		    HostForm.Settings.Password = txtPassword.Text;
			SettingsFactory.SaveSettings(HostForm.Settings);
			//
			MessageBox.Show(
                ResourceManager.Instance.GetString(@"DialogUserInfoSaveSucces"),
                ResourceManager.Instance.GetString(@"DialogConfirmation"),
                MessageBoxButtons.OK, MessageBoxIcon.Asterisk,
			                MessageBoxDefaultButton.Button1);
			//
			HostForm.NavigateBack(this, string.Empty);
        }

        #endregion events

    }
}
